<template>
  <div>
    <el-row :gutter="10">
      <el-col :span="24">
        <el-card shadow="never" class="card">
          <div id="charts_one" style="width:100%;min-height:80vh">
            <Search size='small' :searchVisible="searchVisible" :searchData.sync="searchData"  :searchForm="searchForm" @refresh_list="index"></Search>
            <div class="btn-group" style="margin-bottom:11px;">
              <div>

              </div>
              <table-tool :searchVisible.sync="searchVisible"  :fieldList="fieldList" @refresh_list="index" :searchTool="true"></table-tool>
            </div>
            <el-table :row-class-name="rowClass" @selection-change="selection"  @row-click="handleRowClick"  row-key="Id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" v-loading="loading"  ref="multipleTable" border class="eltable" :data="list"  style="width: 100%">
              <el-table-column align="center" type="selection" width="42"></el-table-column>
              <el-table-column align="center" type='' v-if="fieldList[0].checked" property="Id" label="ID" show-overflow-tooltip width="70">
              </el-table-column>
              <el-table-column align="center"  property="mobillno" label="制令单号" show-overflow-tooltip width="" >
              </el-table-column>
              <el-table-column align="center"  property="workshopname" label="车间" show-overflow-tooltip width="" >
              </el-table-column>
              <el-table-column align="center"  property="fspecification" label="件号" show-overflow-tooltip width="" >
              </el-table-column>
              <el-table-column align="center" property="trayno" label="托号" show-overflow-tooltip width="" >
              </el-table-column>
              <el-table-column align="center" property="tray.serial" label="涂程" show-overflow-tooltip width="" >
              </el-table-column>
              <el-table-column align="center" property="tray.fqty" label="数量" show-overflow-tooltip width="" >
              </el-table-column>

              <el-table-column align="center"  property="isprint" label="打印状态" show-overflow-tooltip width="" >
                <template slot-scope="scope">
                  <el-tag type="danger" v-if="scope.row.isprint === true" size="mini" effect="dark">已打</el-tag>
                  <el-tag type="success" v-if="scope.row.isprint === false" size="mini" effect="dark">未打</el-tag>
                </template>
              </el-table-column>

              <el-table-column :fixed="$store.getters.device !== 'mobile'?'right':false" label="操作" align="center" width="160">
                <template slot-scope="scope">
                  <div v-if="scope.row.id">
                    <el-button size="mini" type="text" @click="updatePrint(scope.row)"  style="color:#0066FF" ><i class="el-icon-view" />修改打印</el-button>
                  </div>
                </template>
              </el-table-column>

            </el-table>
            <Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="index" />
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!--添加-->
    <Add  :show.sync="dialog.addDialogStatus" size="small" @refresh_list="index"></Add>
    <!--修改-->
    <Update :info="updateInfo" :show.sync="dialog.updateDialogStatus" size="small" @refresh_list="index"></Update>
    <!--查看详情-->
    <Detail :info="detailInfo" :show.sync="dialog.detailDialogStatus" size="small" @refresh_list="index"></Detail>
  </div>
</template>
<script>
import {
  updateExt,
  getUpdateInfo,
  updatePrint, detailIndex
} from '@/api/app/prdpick'
import Search from '@/components/common/Search.vue'
import Page from '@/components/common/Page.vue'
import TableTool from '@/components/common/TableTool.vue'
import { confirm,param2Obj } from '@/utils/common'
import Add from '@/views/app/prdpick/add.vue'
import Update from '@/views/app/prdpick/update.vue'
import Detail from '@/views/app/prdpick/detail.vue'
export default {
  name:'prdPick',
  components: {
    Search,
    Page,
    TableTool,
    Add,
    Update,
    Detail,
  },
  data(){
    return {
      dialog: {
        addDialogStatus : false,
        updateDialogStatus : false,
        detailDialogStatus : false,
      },
      fieldList:[
        {lable:'ID',checked:false},
        {lable:this.$t('field.PrdPick_FBillNo'),checked:true},
        {lable:this.$t('field.PrdPick_FKdBillNo'),checked:true},
        {lable:this.$t('field.PrdPick_FDate'),checked:true},
        {lable:this.$t('field.PrdPick_FBillNoMo'),checked:true},
        {lable:this.$t('field.PrdPick_FCreateuser'),checked:true},
        {lable:this.$t('field.PrdPick_JoinMaterialName'),checked:true},
        {lable:this.$t('field.PrdPick_JoinMaterialNo'),checked:false},
        {lable:this.$t('field.PrdPick_JoinUnitName'),checked:true},
        {lable:this.$t('field.PrdPick_JoinUnitNo'),checked:false},
        {lable:this.$t('field.PrdPick_FWorkShopNo'),checked:true},
        {lable:this.$t('field.PrdPick_FWorkShopName'),checked:false},
        {lable:this.$t('field.PrdPick_CreateTime'),checked:true},
        {lable:this.$t('field.PrdPick_FState'),checked:true},
      ],
      ids: [],
      selectRows:[],
      selectTotal:0,
      single:true,
      multiple:true,
      list: [],
      small_tables:{},
      addInfo:{},
      updateInfo:{},
      detailInfo:{},
      loading: false,
      page_data: {
        limit: 20,
        page: 1,
        total:20,
      },
      searchVisible:true,
      searchForm:[],
      searchData:{},
    }
  },
  methods: {
    //修改打印状态
    updatePrint(row){
      updatePrint({id:row.id}).then(res => {
        if (res.data){
          this.$message({
            type: 'success',
            message: '修改成功!'
          });
          this.index()
        }
      })
    },
    index(){
      let param = {limit:this.page_data.limit,page:this.page_data.page}
      Object.assign(param, this.searchData,param2Obj(this.$route.fullPath))
      this.loading = true
      detailIndex(param).then(res => {
        this.list = res.data.data
        this.small_tables=res.sql_field_data
        this.page_data.total = res.data.total
        this.loading = false
        if(this.page_data.page == 1){
          this.searchForm = [
            {type:'Input',label:'制令单号',prop:'moBillNo',width:'150px'},
            {type:'Input',label:'车间',prop:'workShopName',width:'150px'},
            {type:'Input',label:'托号',prop:'trayNo',width:'150px'}
          ]
        }
      })
    },
    updateExt(row,field){
      if(row.id){
        updateExt({id:row.id,[field]:row[field]}).then(res => {
          this.$message({message: this.$t('system.success'), type: 'success'})
        })
      }
    },
    add(){
      this.dialog.addDialogStatus = true
    },
    update(row){
      let id = row.id ? row.id : this.ids.join(',')
      getUpdateInfo({id:id}).then(res => {
        if(res.status == 200){
          this.dialog.updateDialogStatus = true
          this.updateInfo = res.data
        }
      })
    },

    detail(row){
      this.detailInfo = {billNo:row.fbillno }
      console.log('11111:',row.fbillno)
      this.dialog.detailDialogStatus = true
    },
    selection(selection) {
      this.selectRows=selection
      this.selectTotal=selection.length
      this.ids = selection.map(item => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    handleRowClick(row, rowIndex,event){
      if(event.target.className !== 'el-input__inner'){
        this.$refs.multipleTable.toggleRowSelection(row)
      }
    },
    rowClass ({ row, rowIndex }) {
      for(let i=0;i<this.ids.length;i++) {
        if (row.id === this.ids[i]) {
          return 'rowLight'
        }
      }
    },
  },
  mounted(){
    this.index()
  }
}
</script>
<style  lang="scss">
@import '@/assets/scss/common.scss';
</style>